`
https://leetcode.cn/problems/sort-colors/
`

/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var sortColors = function (nums) {
  let p0 = 0, p2 = nums.length - 1
  let p = 0
  while (p <= p2) {
    if (nums[p] === 0) {
      [nums[p0], nums[p]] = [nums[p], nums[p0]]
      p0++
    } else if (nums[p] === 2) {
      [nums[p2], nums[p]] = [nums[p], nums[p2]]
      p2--
    } else if (nums[p] === 1) {
      p++
    }

    // 因为小于 p0 都是 0，所以 p 不要小于 p0
    if (p < p0) {
      p = p0;
    }
  }
};